<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>箭头函数的this指向</title>
</head>
<body>
    <script>
    const Jelly = {
        name:'Jelly',
        hobbies:['Coding','Game','Swimming','running'],
        printHobbies:function() {
            this.hobbies.map(hobby=>{
                console.log(`${this.name} loves ${this.hobbies}`);
            })
        }
    }
    Jelly.printHobbies();
    

    //定义方法的默认参数
    //如果参数传入的是undefined函数自动使用默认值,但不能传入null
    let getNum = (a = 5, b = 6)=>{
      return a + b
    }
    console.log(getNum(undefined,6));
    console.log(getNum(4,6));
    
    </script>
    <!-- 
     map方法是一个独立的区块,所以里面的this会指向window
     如果使用let that = this 或者 => 箭头函数即可解决
     箭头函数没有自己的this值,所有会继承他的父作用域
     一个对象或者构造函数不可以使用箭头函数

     -->
</body>
</html>